package com.healthcloud.controller.modules.losewisdom;


import com.healthcloud.dto.req.losewisdom.LoseWisdomFollowUpListReq;
import com.healthcloud.dto.req.losewisdom.LoseWisdomListReq;
import com.healthcloud.dto.req.losewisdom.LoseWisdomMmseListDto;
import com.healthcloud.entity.MsgVo;
import com.healthcloud.entity.losewisdom.LoseWisdomFollowUpEntity;
import com.healthcloud.entity.losewisdom.LoseWisdomMmseEntity;
import com.healthcloud.service.losewisdom.LoseWisdomMmseService;
import com.healthcloud.utils.ApiRes;
import com.healthcloud.utils.PageParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 失智老人问卷调查
 */
@Controller
@RequestMapping("/lose/wisdom/questionnaire")
public class LWQuestionnaireController {

    private static String prefix = "losewisdom/questionnaire";

    @Autowired
    private LoseWisdomMmseService mmseService;

    @GetMapping("/index")
    public String index(){
        return prefix + "/questionnaire";
    }

    @ApiOperation("跳转至更多页面")
    @GetMapping("/more")
    public String more() {
        return prefix + "/more";
    }

    @ApiOperation("跳转至修改页面")
    @GetMapping("/toUpdate")
    public String toUpdate(@RequestParam("id")Integer id, ModelMap map) {
        LoseWisdomMmseEntity entity = mmseService.queryObject(id);
        map.put("entity", entity);
        return prefix + "/update";
    }


    /**
     * 获取MMSE检查问卷列表
     * @param req
     * @param pageParam
     * @return
     */
    @ApiOperation("获取MMSE检查问卷列表")
    @PostMapping("/mmse/list")
    @ResponseBody
    public MsgVo list(LoseWisdomListReq req, @ModelAttribute("pageParam") PageParam pageParam) {
        List<LoseWisdomMmseListDto> list = mmseService.queryList(req, pageParam);
        int count = mmseService.queryTotal(req);
        return new MsgVo(list,count,count,pageParam.getsEcho());
    }

    /**
     * 获取MMSE检查问卷详情
     * @param id
     * @return
     */
    @ApiOperation("获取MMSE检查问卷详情")
    @PostMapping("/mmse/detail")
    @ResponseBody
    public ApiRes getById(Integer id) {
        LoseWisdomMmseEntity entity = mmseService.queryObject(id);
        return ApiRes.success(entity);
    }

    /**
     * 新增MMSE检查问卷记录
     * @param entity
     * @return
     */
    @ApiOperation("新增MMSE检查问卷记录")
    @PostMapping("/mmse/save")
    @ResponseBody
    public ApiRes save(LoseWisdomMmseEntity entity) {
        mmseService.save(entity);
        return ApiRes.success();
    }

    /**
     * 修改MMSE检查问卷记录
     * @param entity
     * @return
     */
    @ApiOperation("修改MMSE检查问卷记录")
    @PostMapping("/mmse/update")
    @ResponseBody
    public ApiRes update(LoseWisdomMmseEntity entity) {
        mmseService.update(entity);
        return ApiRes.success();
    }

    /**
     * 删除MMSE检查问卷记录
     * @param id
     * @return
     */
    @ApiOperation("删除MMSE检查问卷记录")
    @PostMapping("/mmse/delete")
    @ResponseBody
    public ApiRes delete(Integer id) {
        mmseService.delete(id);
        return ApiRes.success();
    }
}
